
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>第5章 链接脚本分析 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-intopic-toc/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../06_启动文件分析/06_启动文件分析.html" />
    
    
    <link rel="prev" href="../04_CH32V307编译过程分析/04_CH32V307编译过程分析.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../01_初识RISC-V/01_初识RISC-V.html">
            
                <a href="../01_初识RISC-V/01_初识RISC-V.html">
            
                    
                    第1章 初识RISC-V
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../02_开发环境搭建/02_开发环境搭建.html">
            
                <a href="../02_开发环境搭建/02_开发环境搭建.html">
            
                    
                    第2章 开发环境搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../03_CH32V307下载与调试/03_CH32V307下载与调试.html">
            
                <a href="../03_CH32V307下载与调试/03_CH32V307下载与调试.html">
            
                    
                    第3章 CH32V307下载与调试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../04_CH32V307编译过程分析/04_CH32V307编译过程分析.html">
            
                <a href="../04_CH32V307编译过程分析/04_CH32V307编译过程分析.html">
            
                    
                    第4章 CH32V307编译过程分析
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6" data-path="05_链接脚本分析.html">
            
                <a href="05_链接脚本分析.html">
            
                    
                    第5章 链接脚本分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../06_启动文件分析/06_启动文件分析.html">
            
                <a href="../06_启动文件分析/06_启动文件分析.html">
            
                    
                    第6章 启动文件分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../07_MRS手动新建工程/07_MRS手动新建工程.html">
            
                <a href="../07_MRS手动新建工程/07_MRS手动新建工程.html">
            
                    
                    第7章 MRS手动新建工程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../08_使用寄存器点亮LED-C语言版/08_使用寄存器点亮LED-C语言版.html">
            
                <a href="../08_使用寄存器点亮LED-C语言版/08_使用寄存器点亮LED-C语言版.html">
            
                    
                    第8章 使用寄存器点亮LED-C语言版
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../09_RISC-V汇编语言讲解/09_RISC-V汇编语言讲解.html">
            
                <a href="../09_RISC-V汇编语言讲解/09_RISC-V汇编语言讲解.html">
            
                    
                    第9章 RISC-V汇编语言讲解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../10_使用寄存器点亮LED-汇编版/10_使用寄存器点亮LED-汇编版.html">
            
                <a href="../10_使用寄存器点亮LED-汇编版/10_使用寄存器点亮LED-汇编版.html">
            
                    
                    第10章 使用寄存器点亮LED-汇编版
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >第5章 链接脚本分析</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x7B2C;5&#x7AE0;-&#x94FE;&#x63A5;&#x811A;&#x672C;&#x5206;&#x6790;">&#x7B2C;5&#x7AE0; &#x94FE;&#x63A5;&#x811A;&#x672C;&#x5206;&#x6790;</h1>
<h2 id="51-&#x4EC0;&#x4E48;&#x662F;&#x94FE;&#x63A5;&#x811A;&#x672C;&#xFF1F;">5.1 &#x4EC0;&#x4E48;&#x662F;&#x94FE;&#x63A5;&#x811A;&#x672C;&#xFF1F;</h2>
<p>&#x901A;&#x5E38;&#xFF0C;&#x7A0B;&#x5E8F;&#x7F16;&#x8BD1;&#x7684;&#x6700;&#x540E;&#x4E00;&#x6B65;&#x5C31;&#x662F;<strong>&#x94FE;&#x63A5;</strong>&#xFF0C;&#x6B64;&#x8FC7;&#x7A0B;&#x6839;&#x636E;<strong>&#x201C;*.ld&#x201D;</strong>&#x94FE;&#x63A5;&#x6587;&#x4EF6;&#x5C06;&#x591A;&#x4E2A;&#x76EE;&#x6807;&#x6587;&#x4EF6;<strong>(.o)</strong>&#x548C;&#x5E93;&#x6587;&#x4EF6;<strong>(.a)</strong>&#x8F93;&#x5165;&#x6587;&#x4EF6;&#x94FE;&#x63A5;&#x6210;&#x4E00;&#x4E2A;&#x53EF;&#x6267;&#x884C;&#x8F93;&#x51FA;&#x6587;&#x4EF6;<strong>(.elf)</strong>&#x3002;&#x6D89;&#x53CA;&#x5230;&#x5BF9;<strong>&#x7A7A;&#x95F4;&#x548C;&#x5730;&#x5740;&#x7684;&#x5206;&#x914D;</strong>&#x4EE5;&#x53CA;<strong>&#x7B26;&#x53F7;&#x89E3;&#x6790;&#x4E0E;&#x91CD;&#x5B9A;&#x4F4D;</strong>&#x3002;</p>
<p>&#x800C;ld&#x94FE;&#x63A5;&#x811A;&#x672C;&#x63A7;&#x5236;&#x8FD9;&#x6574;&#x4E2A;&#x94FE;&#x63A5;&#x8FC7;&#x7A0B;&#xFF0C;&#x4E3B;&#x8981;&#x7528;&#x4E8E;&#x89C4;&#x5B9A;&#x5404;&#x8F93;&#x5165;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x7A0B;&#x5E8F;&#x3001;&#x6570;&#x636E;&#x7B49;&#x5185;&#x5BB9;&#x6BB5;&#x5728;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x7A7A;&#x95F4;&#x548C;&#x5730;&#x5740;&#x5982;&#x4F55;&#x5206;&#x914D;&#x3002;&#x901A;&#x4FD7;&#x7684;&#x8BB2;&#xFF0C;&#x94FE;&#x63A5;&#x811A;&#x672C;&#x7528;&#x4E8E;&#x63CF;&#x8FF0;&#x8F93;&#x5165;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x6BB5;&#xFF0C;&#x5C06;&#x5176;&#x6620;&#x5C04;&#x5230;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x5E76;&#x6307;&#x5B9A;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x5185;&#x5B58;&#x5206;&#x914D;&#x3002;</p>
<p><img src="image/text_data_bss.png" alt=""></p>
<h2 id="52-&#x94FE;&#x63A5;&#x811A;&#x672C;&#x7684;&#x4E3B;&#x8981;&#x5185;&#x5BB9;">5.2 &#x94FE;&#x63A5;&#x811A;&#x672C;&#x7684;&#x4E3B;&#x8981;&#x5185;&#x5BB9;</h2>
<h3 id="521-&#x94FE;&#x63A5;&#x914D;&#x7F6E;&#x53EF;&#x9009;">5.2.1 &#x94FE;&#x63A5;&#x914D;&#x7F6E;(&#x53EF;&#x9009;)</h3>
<p>&#x5E38;&#x89C1;&#x7684;&#x914D;&#x7F6E;&#x6709;&#x5165;&#x53E3;&#x5730;&#x5740;&#x3001;&#x8F93;&#x51FA;&#x683C;&#x5F0F;&#x3001;&#x7B26;&#x53F7;&#x53D8;&#x91CF;&#x7684;&#x5B9A;&#x4E49;&#x7B49;&#x3002;&#x5982;&#xFF1A;</p>
<pre><code>ENTRY( _start ) /* &#x5165;&#x53E3;&#x5730;&#x5740; */ 

__stack_size = 2048; /* &#x5B9A;&#x4E49;&#x6808;&#x5927;&#x5C0F; */
PROVIDE( _stack_size = __stack_size );/* &#x5B9A;&#x4E49;_stack_size&#x7B26;&#x53F7;&#xFF0C;&#x7C7B;&#x4F3C;&#x4E8E;&#x5168;&#x5C40;&#x53D8;&#x91CF; */
</code></pre><h3 id="522-&#x5185;&#x5B58;&#x5E03;&#x5C40;&#x5B9A;&#x4E49;">5.2.2 &#x5185;&#x5B58;&#x5E03;&#x5C40;&#x5B9A;&#x4E49;</h3>
<p>&#x5BF9;MCU&#x7684;Flash&#x53CA;RAM&#x7A7A;&#x95F4;&#x8FDB;&#x884C;&#x5206;&#x914D;&#xFF0C;&#x5176;&#x4E2D;&#x4EE5;<strong>ORIGIN</strong>&#x5B9A;&#x4E49;&#x5730;&#x5740;&#x7A7A;&#x95F4;&#x7684;&#x8D77;&#x59CB;&#x5730;&#x5740;&#xFF0C;<strong>LENGTH</strong>&#x5B9A;&#x4E49;&#x5730;&#x5740;&#x7A7A;&#x95F4;&#x7684;&#x957F;&#x5EA6;&#x3002;</p>
<p>&#x8BED;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code>MEMORY
{
    name[(attr)] : ORIGIN = origin, LENGTH = length
    ...
}
</code></pre><blockquote>
<p>&#x8FD9;&#x91CC;&#x7684;<strong>attr</strong>&#x53EA;&#x80FD;&#x7531;&#x4EE5;&#x4E0B;&#x7279;&#x6027;&#x7EC4;&#x6210;</p>
<p><strong>&apos;R&apos;</strong> - Read-only section</p>
<p><strong>&apos;W&apos;</strong> - Read/write section</p>
<p><strong>&apos;X&apos;</strong> - Executable section</p>
<p><strong>&apos;A&apos;</strong> - Allocatable section</p>
<p><strong>&apos;I&apos;</strong> - Initialized section</p>
<p><strong>&apos;L&apos;</strong> - Same as I</p>
<p><strong>&apos;&apos;!&apos;&apos;</strong> - Invert the sense of any of the attributes that follow</p>
</blockquote>
<h3 id="523-&#x6BB5;&#x94FE;&#x63A5;&#x5B9A;&#x4E49;">5.2.3 &#x6BB5;&#x94FE;&#x63A5;&#x5B9A;&#x4E49;</h3>
<p>&#x7528;&#x4E8E;&#x5B9A;&#x4E49;&#x76EE;&#x6807;&#x6587;&#x4EF6;<strong>(.o)</strong>&#x7684;<strong>text</strong>&#x3001;<strong>data</strong>&#x3001;<strong>bss</strong>&#x7B49;&#x6BB5;&#x7684;&#x94FE;&#x63A5;&#x5206;&#x5E03;&#x3002;&#x8BED;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code>SECTIONS
{
    section [address] [(type)] :
    [AT(lma)]
    [ALIGN(section_align) | ALIGN_WITH_INPUT]
    [SUBALIGN(subsection_align)]
    [constraint]
    {
        output-section-command
        output-section-command
        ...
    } [&gt;region] [AT&gt;lma_region] [:phdr :phdr ...] [=fillexp] [,]

    ...
}

/* &#x5927;&#x591A;&#x6570;&#x7684;&#x6BB5;&#x4EC5;&#x4F7F;&#x7528;&#x4E86;&#x4E0A;&#x8FF0;&#x90E8;&#x5206;&#x5C5E;&#x6027;&#xFF0C;&#x53EF;&#x4EE5;&#x7B80;&#x5199;&#x6210;&#x5982;&#x4E0B;&#x5F62;&#x5F0F; */
SECTIONS
{
      ...
      secname :
      { 
        output-section-command 
      } 
      ...
}
</code></pre><p>&#x94FE;&#x63A5;&#x811A;&#x672C;&#x672C;&#x8D28;&#x5C31;&#x662F;&#x63CF;&#x8FF0;&#x8F93;&#x5165;&#x548C;&#x8F93;&#x51FA;&#x3002;<strong>secname</strong>&#x8868;&#x793A;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x7684;&#x6BB5;&#xFF0C;&#x800C;<strong>output-section-command</strong>&#x7528;&#x6765;&#x63CF;&#x8FF0;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x7684;&#x8FD9;&#x4E2A;&#x6BB5;&#x4ECE;&#x54EA;&#x4E9B;&#x6587;&#x4EF6;&#x91CC;&#x62BD;&#x53D6;&#x800C;&#x6765;&#xFF0C;&#x5373;&#x8F93;&#x5165;&#x76EE;&#x6807;&#x6587;&#x4EF6;<strong>(.o)</strong>&#x548C;&#x5E93;&#x6587;&#x4EF6;<strong>(.a)</strong>&#x3002;</p>
<p><strong>Section</strong> &#x5206;&#x4E3A;<strong>loadable</strong>(&#x53EF;&#x52A0;&#x8F7D;)&#x548C;<strong>allocatable</strong>(&#x53EF;&#x5206;&#x914D;)&#x4E24;&#x79CD;&#x7C7B;&#x578B;&#x3002;&#x4E0D;&#x53EF;&#x52A0;&#x8F7D;&#x4E5F;&#x4E0D;&#x53EF;&#x5206;&#x914D;&#x7684;&#x5185;&#x5B58;&#x6BB5;&#xFF0C;&#x901A;&#x5E38;&#x5305;&#x542B;&#x4E00;&#x4E9B;&#x8C03;&#x8BD5;&#x7B49;&#x4FE1;&#x606F;&#x3002;
<strong>loadable</strong>&#xFF1A;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x65F6;&#xFF0C;&#x8BE5;&#x6BB5;&#x5E94;&#x8BE5;&#x88AB;&#x52A0;&#x8F7D;&#x5230;&#x5185;&#x5B58;&#x4E2D;&#x3002;
<strong>allocatable</strong>&#xFF1A;&#x8BE5;&#x6BB5;&#x5185;&#x5BB9;&#x88AB;&#x9884;&#x7559;&#x51FA;&#xFF0C;&#x540C;&#x65F6;&#x4E0D;&#x5E94;&#x8BE5;&#x52A0;&#x8F7D;&#x4EFB;&#x4F55;&#x5176;&#x4ED6;&#x5185;&#x5BB9;&#xFF08;&#x67D0;&#x4E9B;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x8FD9;&#x4E9B;&#x5185;&#x5B58;&#x5FC5;&#x987B;&#x5F52;&#x96F6;&#xFF09;&#x3002;</p>
<p>loadable&#x548C;allocatable&#x7684;section&#x90FD;&#x6709;&#x4E24;&#x4E2A;&#x5730;&#x5740;&#xFF1A;&quot;<strong>VMA</strong>&quot;&#x548C;&quot;<strong>LMA</strong>&quot;&#x3002;
<strong>VMA</strong> (the vortual memory address)&#xFF1A;&#x8FD0;&#x884C;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x65F6;&#xFF0C;&#x8BE5;section&#x7684;&#x5730;&#x5740;&#x3002;&#x53EF;&#x9009;&#x9879;&#xFF0C;&#x53EF;&#x4E0D;&#x914D;&#x7F6E;&#x3002;
 <strong>LAM</strong> (load memory address)&#xFF1A;&#x52A0;&#x8F7D;section&#x65F6;&#x7684;&#x5730;&#x5740;&#x3002;
<strong>&#x5728;&#x5927;&#x591A;&#x6570;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x8FD9;&#x4E24;&#x4E2A;&#x5730;&#x5740;&#x65F6;&#x76F8;&#x540C;&#x7684;</strong>&#x3002;&#x4F46;&#x6709;&#x4E9B;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x9700;&#x5C06;&#x4EE3;&#x7801;&#x4ECE;Flash&#x4E2D;&#x52A0;&#x8F7D;&#x81F3;RAM&#x8FD0;&#x884C;&#xFF0C;&#x6B64;&#x65F6;Flash&#x5730;&#x5740;&#x4E3A;LAM&#xFF0C;RAM&#x5730;&#x5740;&#x4E3A;VMA&#x3002;&#x5982;&#xFF1A;</p>
<pre><code>.data :
    {
        *(.data .data.*)
        . = ALIGN(8);
        PROVIDE( __global_pointer$ = . + 0x800 );
        *(.sdata .sdata.*)
        *(.sdata2.*)
        . = ALIGN(4);
        PROVIDE( _edata = .);
    } &gt;RAM AT&gt;FLASH
</code></pre><p>&#x4E0A;&#x8FF0;&#x793A;&#x4F8B;&#x4E2D;&#xFF0C;.data&#x6BB5;&#x7684;&#x5185;&#x5BB9;&#x4F1A;&#x653E;&#x5728;Flash&#x4E2D;&#xFF0C;&#x4F46;&#x662F;&#x8FD0;&#x884C;&#x65F6;&#xFF0C;&#x4F1A;&#x52A0;&#x8F7D;&#x81F3;RAM&#x4E2D;&#xFF08;&#x901A;&#x5E38;&#x4E3A;&#x521D;&#x59CB;&#x5316;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF09;&#xFF0C;&#x5373;<strong>.data&#x6BB5;&#x7684;VMA&#x4E3A;RAM&#xFF0C;LMA&#x4E3A;Flash</strong>&#x3002;</p>
<h2 id="53-&#x5E38;&#x7528;&#x5173;&#x952E;&#x5B57;&#x53CA;&#x547D;&#x4EE4;">5.3 &#x5E38;&#x7528;&#x5173;&#x952E;&#x5B57;&#x53CA;&#x547D;&#x4EE4;</h2>
<h3 id="531-entry">5.3.1 ENTRY</h3>
<p>&#x8BED;&#x6CD5;&#xFF1A;ENTRY(symbol)&#xFF0C;&#x7A0B;&#x5E8F;&#x4E2D;&#x8981;&#x6267;&#x884C;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x6307;&#x4EE4;&#xFF0C;&#x4E5F;&#x79F0;&#x5165;&#x53E3;&#x70B9;&#x3002;</p>
<p>&#x793A;&#x4F8B;&#xFF1A;</p>
<pre><code>/* Entry Point */
ENTRY( _start ) /* CH32V103&#x4E3A;&#x542F;&#x52A8;&#x6587;&#x4EF6; j handle_reset &#x6307;&#x4EE4;*/
</code></pre><h3 id="532-provide">5.3.2 PROVIDE</h3>
<p>&#x8BED;&#x6CD5;&#xFF1A;PROVIDE (symbol = expression)&#xFF0C;&#x7528;&#x4E8E;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x53EF;&#x88AB;&#x5F15;&#x7528;&#x7684;&#x7B26;&#x53F7;&#xFF0C;&#x7C7B;&#x4F3C;&#x4E8E;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x3002;&#x793A;&#x4F8B;&#xFF1A;</p>
<pre><code>PROVIDE( end = . );
</code></pre><h3 id="533-hidden">5.3.3 HIDDEN</h3>
<p>&#x8BED;&#x6CD5;&#xFF1A;HIDDEN (symbol = expression)&#xFF0C;&#x5BF9;&#x4E8E;ELF&#x76EE;&#x6807;&#x7AEF;&#x53E3;&#xFF0C;&#x7B26;&#x53F7;&#x5C06;&#x88AB;&#x9690;&#x85CF;&#x4E14;&#x4E0D;&#x88AB;&#x5BFC;&#x51FA;&#x3002;&#x793A;&#x4F8B;&#xFF1A;</p>
<pre><code>HIDDEN (mySymbol = .);
</code></pre><h3 id="534-providehidden">5.3.4 PROVIDE_HIDDEN</h3>
<p>&#x8BED;&#x6CD5;&#xFF1A;PROVIDE_HIDDEN (symbol = expression)&#xFF0C;&#x662F;PROVIDE &#x548C;HIDDEN&#x7684;&#x7ED3;&#x5408;&#x4F53;&#xFF0C;&#x7C7B;&#x4F3C;&#x4E8E;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x3002;&#x793A;&#x4F8B;&#xFF1A;</p>
<pre><code>PROVIDE_HIDDEN (__preinit_array_start = .);
</code></pre><h3 id="535-&#x70B9;&#x4F4D;&#x7B26;&#x53F7;-">5.3.5 &#x70B9;&#x4F4D;&#x7B26;&#x53F7; &apos;.&apos;</h3>
<p>&#x2018;.&#x2019;&#x8868;&#x793A;&#x5F53;&#x524D;&#x5730;&#x5740;&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;&#x603B;&#x662F;&#x4EE3;&#x8868;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x5730;&#x5740;&#xFF08;&#x6839;&#x636E;&#x8F93;&#x5165;&#x6587;&#x4EF6;section&#x7684;&#x5927;&#x5C0F;&#x4E0D;&#x65AD;&#x589E;&#x52A0;&#xFF0C;&#x4E0D;&#x80FD;&#x5012;&#x9000;&#xFF0C;&#x4E14;&#x53EA;&#x7528;&#x4E8E;SECTIONS&#x6307;&#x4EE4;&#x4E2D;&#xFF09;&#x3002;&#x5B83;&#x53EF;&#x4EE5;&#x88AB;&#x8D4B;&#x503C;&#x4E5F;&#x53EF;&#x4EE5;&#x8D4B;&#x503C;&#x7ED9;&#x67D0;&#x4E2A;&#x53D8;&#x91CF;&#xFF1B;&#x4E5F;&#x53EF;&#x8FDB;&#x884C;&#x7B97;&#x672F;&#x8FD0;&#x7B97;&#x7528;&#x4E8E;&#x4EA7;&#x751F;&#x6307;&#x5B9A;&#x957F;&#x5EA6;&#x7684;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x3002;&#x793A;&#x4F8B;&#xFF1A;</p>
<pre><code>PROVIDE( end = . );   /* &#x5F53;&#x524D;&#x5730;&#x5740;&#x8D4B;&#x503C;&#x7ED9; end&#x7B26;&#x53F7; */

.stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size :
{
    . = ALIGN(4); 
    PROVIDE(_susrstack = . );
    . = . + __stack_size;    /* &#x5F53;&#x524D;&#x5730;&#x5740;&#x52A0;&#x4E0A;__stack_size&#x957F;&#x5EA6;&#xFF0C;&#x4EA7;&#x751F;__stack_size&#x957F;&#x5EA6;&#x7684;&#x7A7A;&#x95F4;*/
    PROVIDE( _eusrstack = .);
} &gt;RAM
</code></pre><h3 id="536-keep">5.3.6 KEEP</h3>
<p>&#x5F53;&#x94FE;&#x63A5;&#x5668;&#x4F7F;&#x7528;&#xFF08;&apos;--gc-sections&apos;&#xFF09;&#x8FDB;&#x884C;&#x5783;&#x573E;&#x56DE;&#x6536;&#x65F6;&#xFF0C;KEEP()&#x53EF;&#x4EE5;&#x4F7F;&#x5F97;&#x88AB;&#x6807;&#x8BB0;&#x6BB5;&#x7684;&#x5185;&#x5BB9;&#x4E0D;&#x88AB;&#x6E05;&#x695A;&#x3002;&#x793A;&#x4F8B;</p>
<pre><code>.init :
{
    _sinit = .;
    . = ALIGN(4);
    KEEP(*(SORT_NONE(.init))) 
    . = ALIGN(4);
    _einit = .;
} &gt;FLASH AT&gt;FLASH
</code></pre><h3 id="537-assert">5.3.7 ASSERT</h3>
<p>&#x8BED;&#x6CD5;&#xFF1A;ASSERT(exp, message)&#xFF0C;&#x786E;&#x4FDD;exp&#x662F;&#x975E;&#x96F6;&#x503C;&#xFF0C;&#x5982;&#x679C;&#x4E3A;&#x96F6;&#xFF0C;&#x5C06;&#x4EE5;&#x9519;&#x8BEF;&#x7801;&#x7684;&#x5F62;&#x5F0F;&#x9000;&#x51FA;&#x94FE;&#x63A5;&#x6587;&#x4EF6;&#xFF0C;&#x5E76;&#x8F93;&#x51FA;message&#x3002;&#x4E3B;&#x8981;&#x7528;&#x4E8E;&#x6DFB;&#x52A0;&#x65AD;&#x8A00;&#xFF0C;&#x5B9A;&#x4F4D;&#x95EE;&#x9898;&#x3002;</p>
<p>&#x793A;&#x4F8B;&#xFF1A;</p>
<pre><code>/* The usage of ASSERT */
PROVIDE (__stack_size = 0x100);

.stack
{
    PROVIDE (__stack = .);
    ASSERT ((__stack &gt; (_end + __stack_size)), &quot;Error: No room left for the stack&quot;);
}
/* &#x5F53;&quot;__stack&quot; &#x5927;&#x4E8E; &quot;_end + __stack_size&quot;&#x65F6;&#xFF0C;&#x5728;&#x94FE;&#x63A5;&#x65F6;&#xFF0C;&#x4F1A;&#x51FA;&#x73B0;&#x9519;&#x8BEF;&#xFF0C;&#x5E76;&#x63D0;&#x793A;&quot;Error: No room left for the stack&quot; */
</code></pre><h2 id="54-&#x5B8C;&#x6574;ld&#x94FE;&#x63A5;&#x811A;&#x672C;&#x793A;&#x4F8B;">5.4 &#x5B8C;&#x6574;ld&#x94FE;&#x63A5;&#x811A;&#x672C;&#x793A;&#x4F8B;</h2>
<p>&#x4EE5;CH32V307&#x4E3A;&#x4F8B;&#xFF1A;</p>
<pre><code>ENTRY( _start )

__stack_size = 2048;

PROVIDE( _stack_size = __stack_size );


MEMORY
{
  FLASH (rx) : ORIGIN = 0x00000000 , LENGTH = 0x48000
  RAM (xrw) : ORIGIN = 0x20000000 , LENGTH = 0x8000
}


SECTIONS
{

    .init :
    {
        _sinit = .;
        . = ALIGN(4);
        KEEP(*(SORT_NONE(.init)))
        . = ALIGN(4);
        _einit = .;
    } &gt;FLASH AT&gt;FLASH

  .vector :
  {
      *(.vector);
      . = ALIGN(64);
  } &gt;FLASH AT&gt;FLASH

    .text :
    {
        . = ALIGN(4);
        *(.text)
        *(.text.*)
        *(.rodata)
        *(.rodata*)
        *(.glue_7)
        *(.glue_7t)
        *(.gnu.linkonce.t.*)
        . = ALIGN(4);
    } &gt;FLASH AT&gt;FLASH 

    .fini :
    {
        KEEP(*(SORT_NONE(.fini)))
        . = ALIGN(4);
    } &gt;FLASH AT&gt;FLASH

    PROVIDE( _etext = . );
    PROVIDE( _eitcm = . );    

    .preinit_array  :
    {
      PROVIDE_HIDDEN (__preinit_array_start = .);
      KEEP (*(.preinit_array))
      PROVIDE_HIDDEN (__preinit_array_end = .);
    } &gt;FLASH AT&gt;FLASH 

    .init_array     :
    {
      PROVIDE_HIDDEN (__init_array_start = .);
      KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
      KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
      PROVIDE_HIDDEN (__init_array_end = .);
    } &gt;FLASH AT&gt;FLASH 

    .fini_array     :
    {
      PROVIDE_HIDDEN (__fini_array_start = .);
      KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
      KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
      PROVIDE_HIDDEN (__fini_array_end = .);
    } &gt;FLASH AT&gt;FLASH 

    .ctors          :
    {
      /* gcc uses crtbegin.o to find the start of
         the constructors, so we make sure it is
         first.  Because this is a wildcard, it
         doesn&apos;t matter if the user does not
         actually link against crtbegin.o; the
         linker won&apos;t look for a file to match a
         wildcard.  The wildcard also means that it
         doesn&apos;t matter which directory crtbegin.o
         is in.  */
      KEEP (*crtbegin.o(.ctors))
      KEEP (*crtbegin?.o(.ctors))
      /* We don&apos;t want to include the .ctor section from
         the crtend.o file until after the sorted ctors.
         The .ctor section from the crtend file contains the
         end of ctors marker and it must be last */
      KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
      KEEP (*(SORT(.ctors.*)))
      KEEP (*(.ctors))
    } &gt;FLASH AT&gt;FLASH 

    .dtors          :
    {
      KEEP (*crtbegin.o(.dtors))
      KEEP (*crtbegin?.o(.dtors))
      KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
      KEEP (*(SORT(.dtors.*)))
      KEEP (*(.dtors))
    } &gt;FLASH AT&gt;FLASH 

    .dalign :
    {
        . = ALIGN(4);
        PROVIDE(_data_vma = .);
    } &gt;RAM AT&gt;FLASH    

    .dlalign :
    {
        . = ALIGN(4); 
        PROVIDE(_data_lma = .);
    } &gt;FLASH AT&gt;FLASH

    .data :
    {
        *(.gnu.linkonce.r.*)
        *(.data .data.*)
        *(.gnu.linkonce.d.*)
        . = ALIGN(8);
        PROVIDE( __global_pointer$ = . + 0x800 );
        *(.sdata .sdata.*)
        *(.sdata2.*)
        *(.gnu.linkonce.s.*)
        . = ALIGN(8);
        *(.srodata.cst16)
        *(.srodata.cst8)
        *(.srodata.cst4)
        *(.srodata.cst2)
        *(.srodata .srodata.*)
        . = ALIGN(4);
        PROVIDE( _edata = .);
    } &gt;RAM AT&gt;FLASH

    .bss :
    {
        . = ALIGN(4);
        PROVIDE( _sbss = .);
          *(.sbss*)
        *(.gnu.linkonce.sb.*)
        *(.bss*)
         *(.gnu.linkonce.b.*)        
        *(COMMON*)
        . = ALIGN(4);
        PROVIDE( _ebss = .);
    } &gt;RAM AT&gt;FLASH

    PROVIDE( _end = _ebss);
    PROVIDE( end = . );

    .stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size :
    {
        . = ALIGN(4);
        PROVIDE(_susrstack = . );
        . = . + __stack_size;
        PROVIDE( _eusrstack = .);
    } &gt;RAM 

}
</code></pre><footer class="page-footer"><span class="copyright">powered by Gitbook</span><span class="footer-modification">File Modify: 
2021-09-28 09:11:12
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../04_CH32V307编译过程分析/04_CH32V307编译过程分析.html" class="navigation navigation-prev " aria-label="Previous page: 第4章 CH32V307编译过程分析">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../06_启动文件分析/06_启动文件分析.html" class="navigation navigation-next " aria-label="Next page: 第6章 启动文件分析">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"第5章 链接脚本分析","level":"1.6","depth":1,"next":{"title":"第6章 启动文件分析","level":"1.7","depth":1,"path":"06_启动文件分析/06_启动文件分析.md","ref":"06_启动文件分析/06_启动文件分析.md","articles":[]},"previous":{"title":"第4章 CH32V307编译过程分析","level":"1.5","depth":1,"path":"04_CH32V307编译过程分析/04_CH32V307编译过程分析.md","ref":"04_CH32V307编译过程分析/04_CH32V307编译过程分析.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["-lunr","-search","-sharing","search-pro","back-to-top-button","chapter-fold","splitter","tbfed-pagefooter","popup","intopic-toc","copy-code-button","github","hide-element","pageview-count","livereload"],"pluginsConfig":{"tbfed-pagefooter":{},"chapter-fold":{},"github":{"url":"https://gitee.com/taoyukai/ch32v307_development_guide"},"intopic-toc":{"isCollapsed":true,"isScrollspyActive":true,"label":"In this article","maxDepth":6,"mode":"nested","selector":".markdown-section h1, .markdown-section h2, .markdown-section h3, .markdown-section h4, .markdown-section h5, .markdown-section h6","visible":true},"livereload":{},"splitter":{},"search-pro":{},"popup":{},"hide-element":{"elements":[".gitbook-link"]},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"back-to-top-button":{},"pageview-count":{},"copy-code-button":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"05_链接脚本分析/05_链接脚本分析.md","mtime":"2021-09-28T01:11:12.597Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-10-12T06:38:50.113Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-intopic-toc/anchor.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-intopic-toc/gumshoe.polyfills.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-intopic-toc/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

